<template>
  <div class="dashboard-container">
    <div class="welcome-section">
      <h2>{{ $t('dashboard.welcome') }}, {{ userInfo.nickname || 'Admin' }}</h2>
      <p class="date-info">{{ currentDate }}</p>
    </div>

    <el-row :gutter="20" class="data-overview">
      <el-col :xs="24" :sm="12" :md="6">
        <el-card shadow="hover" class="data-card"> </el-card>
      </el-col>

      <el-col :xs="24" :sm="12" :md="6">
        <el-card shadow="hover" class="data-card"> </el-card>
      </el-col>

      <el-col :xs="24" :sm="12" :md="6">
        <el-card shadow="hover" class="data-card"> </el-card>
      </el-col>

      <el-col :xs="24" :sm="12" :md="6">
        <el-card shadow="hover" class="data-card"> </el-card>
      </el-col>
    </el-row>

    <el-row :gutter="20" class="dashboard-content">
      <el-col :xs="24" :lg="16">
        <el-card class="chart-card">
          <template #header>
            <div class="card-header">
              <span>{{ $t('dashboard.recentActivity') }}</span>
            </div>
          </template>
          <div class="chart-placeholder">
            <el-empty :description="$t('common.noData')" />
          </div>
        </el-card>
      </el-col>

      <el-col :xs="24" :lg="8">
        <el-card class="quick-actions">
          <template #header>
            <div class="card-header">
              <span>{{ $t('dashboard.quickActions') }}</span>
            </div>
          </template>
          <div class="action-list"></div>
        </el-card>

        <el-card class="system-status" style="margin-top: 20px">
          <template #header>
            <div class="card-header">
              <span>{{ $t('dashboard.systemStatus') }}</span>
            </div>
          </template>
          <div class="status-list"></div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { computed, onMounted } from 'vue';
import { useI18n } from 'vue-i18n';
import { useUserStore } from '@/store/user';

// 国际化
const { t } = useI18n();

// 用户信息
const userStore = useUserStore();
const userInfo = computed(() => userStore.userInfo);

// 当前日期
const currentDate = computed(() => {
  const now = new Date();
  return now.toLocaleDateString(undefined, {
    weekday: 'long',
    year: 'numeric',
    month: 'long',
    day: 'numeric',
  });
});

// 模拟数据加载
onMounted(() => {
  // 这里可以添加实际的数据加载逻辑
});
</script>

<style lang="less" scoped>
.dashboard-container {
  padding: 10px;
}

.welcome-section {
  margin-bottom: 20px;

  h2 {
    font-size: 24px;
    font-weight: 500;
    color: var(--text-color);
    margin-bottom: 8px;
  }

  .date-info {
    font-size: 14px;
    color: var(--info-color);
  }
}

.data-overview {
  margin-bottom: 20px;
}

.data-card {
  height: 120px;
  display: flex;
  align-items: center;
  padding: 20px;
  margin-bottom: 20px;
  transition: all 0.3s;
  background-color: var(--card-bg);
  color: var(--text-color);

  &:hover {
    transform: translateY(-5px);
  }

  .data-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-right: 15px;

    .el-icon {
      font-size: 24px;
      color: #fff;
    }

    &.visits {
      background-color: #409eff;
    }

    &.users {
      background-color: #67c23a;
    }

    &.orders {
      background-color: #e6a23c;
    }

    &.revenue {
      background-color: #f56c6c;
    }
  }

  .data-info {
    flex: 1;

    .data-title {
      font-size: 14px;
      color: var(--info-color);
      margin-bottom: 8px;
    }

    .data-value {
      font-size: 24px;
      font-weight: bold;
      color: var(--text-color);
      margin-bottom: 8px;
    }

    .data-trend {
      display: flex;
      align-items: center;
      font-size: 12px;

      &.up {
        color: #67c23a;
      }

      &.down {
        color: #f56c6c;
      }

      .el-icon {
        margin-right: 4px;
      }
    }
  }
}

.dashboard-content {
  margin-bottom: 20px;
}

.chart-card {
  margin-bottom: 20px;
  background-color: var(--card-bg);
  color: var(--text-color);

  .chart-placeholder {
    height: 350px;
    display: flex;
    justify-content: center;
    align-items: center;
  }
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-color);
}

.quick-actions {
  margin-bottom: 20px;
  background-color: var(--card-bg);
  color: var(--text-color);

  .action-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .action-item {
    .el-button {
      width: 100%;
      justify-content: flex-start;

      .el-icon {
        margin-right: 8px;
      }
    }
  }
}

.system-status {
  background-color: var(--card-bg);
  color: var(--text-color);

  .status-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
  }

  .status-item {
    .status-label {
      display: block;
      margin-bottom: 5px;
      font-size: 14px;
      color: var(--text-color);
    }
  }
}

/* 响应式适配 */
@media screen and (max-width: 768px) {
  .welcome-section {
    h2 {
      font-size: 20px;
    }
  }

  .data-card {
    height: auto;
    padding: 15px;

    .data-icon {
      width: 50px;
      height: 50px;

      .el-icon {
        font-size: 20px;
      }
    }

    .data-info {
      .data-value {
        font-size: 20px;
      }
    }
  }
}

/* 动画效果 */
.dashboard-container {
  animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
</style>
